self.postMessage("Test started.");
// The test will create timeouts in the following order
// on first message - 1s, 2s.
// on second message - 2s, 1s.
// on third and final message - 3s, 2s, 1s.
// if the timeouts in order then the test is PASS.
self.addEventListener('message', function(e) {
    if(e.data == "TS1") {
        setTimeout(function () { postMessage(1); }, 1000);
        setTimeout(function () { postMessage(2); }, 2000);
        setTimeout(function () { postMessage(3); }, 3000);
    }
    else if(e.data == "TS2") {
        setTimeout(function () { postMessage(3); postMessage("DONE");}, 3000);        
        setTimeout(function () { postMessage(2); }, 2000);
        setTimeout(function () { postMessage(1); }, 1000);
    }    
}, false);